home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2002 November / SGI IRIX 6.5 Applications 2002 November.iso / dist / gateway.idb / usr / WebFace / Source / 20-NetworkServices / nsd / adv-attr.cgi.z / adv-attr.cgi
Encoding:
Text File  |  2002-06-12  |  15.3 KB  |  483 lines

  1. #!/usr/bin/perl5
  2. #
  3. # adv-attr.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20.  
  21. # Still to be added:
  22. # parse the nsd.options file
  23.  
  24. BEGIN { require "/usr/WebFace/lib/CGI.pm"; import CGI; }
  25. require "/usr/OnRamp/lib/OnRamp.pm";
  26. require "/usr/OnRamp/lib/java.pm";
  27.  
  28. $query = new CGI;
  29.  
  30. $nsswitch_cf  = "/etc/nsswitch.conf";
  31. $dummy        = "/etc/nsswitch.conf.tmp";
  32. $title        = "Unified Name Service";
  33. $help_page    = "adv-attr-help.html";
  34. $go           = "adv-attr.cgi";
  35.  
  36. $conf_map = $ARGV[0];
  37. $new = $query->param('new_map') if(! $conf_map);
  38.  
  39. $js =
  40. "$js_standard
  41. $js_help
  42. $js_error_box
  43. function checkForm(form) {
  44.     return (true);
  45. }";
  46.  
  47.  
  48. if($query->param('del') eq 'Yes') {
  49.     &delete($conf_map);
  50.     &redirect("adv-config.cgi?return");
  51.     exit(0);
  52. }
  53.  
  54. @lib_order = 
  55.     ($query->param('lib1'), $query->param('lib2'), $query->param('lib3'));
  56.  
  57. if ($query->param('page2')) {
  58.     &make_changes;
  59.     &redirect("adv-config.cgi?return");
  60.     exit(0);
  61. }
  62. @lib_order = &check_order(@lib_order);
  63.  
  64. print $query->header;
  65. &read_attrs;
  66. &generic;
  67.  
  68. sub check_order {
  69.     local(@values) = @_;
  70.     if ($values[0] eq "none") {
  71.         $values[0] = $values[1];
  72.         $values[1] = $values[2];
  73.         $values[2] = "none";
  74.     }
  75.     if ($values[0] eq "none") {
  76.         $values[0] = $values[1];
  77.         $values[1] = "none";
  78.     }
  79.     return @values;
  80. }
  81.  
  82. sub make_changes {
  83.     &set_attrs;
  84.  
  85.     open(NSSWITCH, "$dummy");
  86.     open(TEMP, ">$nsswitch_cf.new");
  87.     if ($new) {
  88.         while ($line = <NSSWITCH>) {
  89.             print TEMP "$line"; 
  90.         }
  91.         &print_line($new);
  92.     } else {
  93.         while ($line = <NSSWITCH>) {
  94.             if ($line =~ /^\s*[#\n]/) { print TEMP "$line"; next; }
  95.             @entlist = split(/\s+/, $line);
  96.             chop ($entlist[0]);
  97.             $entlist[0] =~ s/(\S+)\s*(\(\S+\)*)$/\1/g;
  98.  
  99.             if ($conf_map eq $entlist[0]) { 
  100.                 print TEMP "# $line"; 
  101.                 &print_line($conf_map);
  102.             } else { print TEMP "$line"; }
  103.         }
  104.         
  105.     }
  106.     close(NSSWITCH);
  107.     close(TEMP);
  108.     rename("$nsswitch_cf.new", $dummy);
  109. }
  110.  
  111. sub delete {
  112.     local ($del_map) = @_[0];
  113.     open(NSSWITCH, "$dummy");
  114.     open(TEMP, ">$nsswitch_cf.new");
  115.     while ($line = <NSSWITCH>) {
  116.         if ($line =~ /^\s*[#\n]/) { print TEMP "$line"; next; }
  117.         @entlist = split(/\s+/, $line);
  118.         chop ($entlist[0]);
  119.         $entlist[0] =~ s/(\S+)\s*(\(\S+\)*)$/\1/g;
  120.  
  121.         if ($del_map eq $entlist[0]) { print TEMP "# $line"; } 
  122.         else { print TEMP "$line"; }
  123.     }
  124.     close(NSSWITCH);
  125.     close(TEMP);
  126.     rename("$nsswitch_cf.new", $dummy);
  127. }
  128.  
  129. sub generic {
  130.     &js_title_block($title,$js);
  131.     &header_block($title);
  132.  
  133.     print $query->startform("POST", "$go?$conf_map", "", 
  134.         "NAME=StandardForm", "onSubmit=\"return runSubmit()\"");
  135.  
  136.     print "<i>$message</i><p>\n";
  137.     print "<input type=hidden name=page2 value=yes>\n";
  138.     print "<input type=hidden name=new_map value=\"$new\">\n" if ($new);
  139.     print "<input type=hidden name=lib1 value=\"$lib_order[0]\">\n";
  140.     print "<input type=hidden name=lib2 value=\"$lib_order[1]\">\n";
  141.     print "<input type=hidden name=lib3 value=\"$lib_order[2]\">\n";
  142.     print "<center>
  143.         You have chosen the following order of lookup services:<p>\n";
  144.     if (! $conf_map) {
  145.         print "$new";
  146.     } else {
  147.         print "$conf_map";
  148.     }
  149.     print ": $lib_order[0]";
  150.     print " $lib_order[1]";
  151.     print " $lib_order[2]";
  152.     print "\n<p><hr width=\"50%\"></center><p>
  153.         Now please enter any attributes each service should use 
  154.         for this map.  If you do not enter a value, the default
  155.         (shown in parentheses where available) will be used.<p>
  156.         <center>\n";
  157.     @numbers = ("1", "2", "3", "4");
  158.     $i = 0;
  159.     print "<table width=450>\n";
  160.     &print_global($numbers[$i]);
  161.     $i++;
  162.     foreach $lib (@lib_order) {
  163.         &print_files($numbers[$i]) if($lib eq 'files');    
  164.         &print_dns($numbers[$i]) if($lib eq 'dns');    
  165.         &print_nis($numbers[$i]) if($lib eq 'nis');    
  166.         &print_nisserv($numbers[$i]) if($lib eq 'nisserv');    
  167.         &print_mdbm($numbers[$i]) if($lib eq 'mdbm');    
  168.         &print_ndbm($numbers[$i]) if($lib eq 'ndbm');    
  169.         &print_db($numbers[$i]) if($lib eq 'db');    
  170.         &print_ldap($numbers[$i]) if($lib eq 'ldap');    
  171.         $i++;
  172.     }
  173.     print "</table></center>\n";
  174.  
  175.     print qq|<font size="+1"><center><table>\n|;
  176.  
  177.     print "</tr></table></center>";
  178.     print "<p>\n";
  179.  
  180.     print &js_buttons('doit','Ok','onClick="markOK()"',
  181.         'onClick="markOther()"',
  182.         "onClick=\"do_help('$help_page'); return (false)\"");
  183.     print $query->endform;
  184. }
  185.  
  186. sub print_line {
  187.     &assemble_attrs(1);
  188.     print TEMP "$_[0]$attr_string: ";
  189.     for ($i = length("$$_[0]$attr_string: "); $i < 24; $i += 8) {
  190.         print TEMP "\t";
  191.     }
  192.     # Assemble each library attributes 
  193.     for ($i = 0; $i < 3; $i++) {
  194.         print TEMP "$lib_order[$i]" if ($lib_order[$i] ne "none");
  195.         &assemble_attrs($i+2);
  196.         print TEMP "$attr_string ";
  197.     }
  198.     # Done
  199.     print TEMP "\n";
  200. }
  201.  
  202. sub print_global {
  203.     $n = $_[0];
  204.     print "<tr><td colspan=2><b>$n. Map Attributes:</b>\n";
  205.     print "<tr><td>timeout:<td><input name=global".$n."_timeout
  206.           value=\"$map_attr{'timeout'}\"> (300 s)\n";
  207.     print "<tr><td>mode:<td><input name=global".$n."_mode
  208.           value=\"$map_attr{'mode'}\"> (0666)\n";
  209.     print "<tr><td>local:<td><input name=global".$n."_local
  210.           value=\"$map_attr{'local'}\"> (false)\n";
  211.     print "<tr><td>null_extend_key:<td><input name=global".$n."_null_extend_key
  212.           value=\"$map_attr{'null_extend_key'}\"> (false)\n";
  213.     print "<p>\n";
  214. }
  215.  
  216. sub print_files {
  217.     $n = $_[0];
  218.     print "<tr><td colspan=2><b>$n. Files Attributes:</b>\n";
  219.     print "<tr><td>domain:<td><input name=file".$n."_domain
  220.           value=\"$files_attr{'domain'}\"> \n";
  221.     print "<tr><td>file:<td><input name=file".$n."_file
  222.           value=\"$files_attr{'file'}\"> \n";
  223.     print "<tr><td>compat:<td><input name=file".$n."_compat
  224.           value=\"$files_attr{'compat'}\"> (false)\n";
  225.     print "<tr><td>separator:<td><input name=file".$n."_separator
  226.           value=\"$files_attr{'separator'}\"> (whitespace)\n";
  227.     print "<p>\n";
  228. }
  229.  
  230. sub print_dns {
  231.     $n = $_[0];
  232.     print "<tr><td colspan=2><b>$n. DNS Attributes:</b>\n";
  233.     print "<tr><td>domain:<td><input name=dns".$n."_domain
  234.           value=\"$dns_attr{'domain'}\"> \n";
  235.     print "<tr><td>dns_servers:<td><input name=dns".$n."_dns_servers
  236.           value=\"$dns_attr{'dns_servers'}\"> \n";
  237.     print "<tr><td>dns_search:<td><input name=dns".$n."_dns_search
  238.           value=\"$dns_attr{'dns_search'}\"> \n";
  239.     print "<tr><td>dns_parallel:<td><input name=dns".$n."_dns_parallel
  240.           value=\"$dns_attr{'dns_parallel'}\"> (false)\n";
  241.     print "<tr><td>dns_retries:<td><input name=dns".$n."_dns_retries
  242.           value=\"$dns_attr{'dns_retries'}\"> (3 queries)\n";
  243.     print "<tr><td>dns_timeout:<td><input name=dns".$n."_dns_timeout
  244.           value=\"$dns_attr{'dns_timeout'}\"> (1000 ms)\n";
  245.     print "<p>\n";
  246. }
  247.  
  248. sub print_nis {
  249.     $n = $_[0];
  250.     print "<tr><td colspan=2><b>$n. NIS Attributes:</b>\n";
  251.     print "<tr><td>domain:<td><input name=nis".$n."_domain
  252.           value=\"$nis_attr{'domain'}\"> \n";
  253.     print "<tr><td>nis_multicast:<td><input name=nis".$n."_nis_multicast
  254.           value=\"$nis_attr{'nsi_multicast'}\"> (32 hops)\n";
  255.     print "<tr><td>nis_secure:<td><input name=nis".$n."_nis_secure
  256.           value=\"$nis_attr{'nis_secure'}\"> (false)\n";
  257.     print "<tr><td>nis_servers:<td><input name=nis".$n."_nis_servers
  258.           value=\"$nis_attr{'nis_servers'}\"> \n";
  259.     print "<tr><td>null_extend_key:<td><input name=nis".$n."_null_extend_key
  260.           value=\"$nis_attr{'null_extend_key'}\"> (false)\n";
  261.     print "<p>\n";
  262. }
  263.  
  264. sub print_nisserv {
  265.     $n = $_[0];
  266.     print "<tr><td colspan=2><b>$n. NISSERV Attributes:</b>\n";
  267.     print "<tr><td>domain:<td><input name=yp".$n."_domain
  268.           value=\"$yp_attr{'domain'}\"> \n";
  269.     print "<tr><td>nis_secure:<td><input name=yp".$n."_nis_secure
  270.           value=\"$yp_attr{'nis_secure'}\"> (false)\n";
  271.     print "<p>\n";
  272. }
  273.  
  274. sub print_mdbm {
  275.     $n = $_[0];
  276.     print "<tr><td colspan=2><b>$n. MDBM Attributes:</b>\n";
  277.     print "<tr><td>domain:<td><input name=mdbm".$n."_domain
  278.           value=\"$mdbm_attr{'domain'}\"> \n";
  279.     print "<tr><td>file:<td><input name=mdbm".$n."_file
  280.           value=\"$mdbm_attr{'file'}\"> \n";
  281.     print "<tr><td>null_extend_key:<td><input name=mdbm".$n."_null_extend_key
  282.           value=\"$mdbm_attr{'null_extend_key'}\"> (false)\n";
  283.     print "<p>\n";
  284. }
  285.  
  286. sub print_ndbm {
  287.     $n = $_[0];
  288.     print "<tr><td colspan=2><b>$n. NDBM Attributes:</b>\n";
  289.     print "<tr><td>domain:<td><input name=ndbm".$n."_domain
  290.           value=\"$ndbm_attr{'domain'}\"> \n";
  291.     print "<tr><td>file:<td><input name=ndbm".$n."_file
  292.           value=\"$ndbm_attr{'file'}\"> \n";
  293.     print "<tr><td>null_extend_key:<td><input name=ndbm".$n."_null_extend_key
  294.           value=\"$ndbm_attr{'null_extend_key'}\"> (false)\n";
  295.     print "<p>\n";
  296. }
  297.  
  298. sub print_db {
  299.     $n = $_[0];
  300.     print "<tr><td colspan=2><b>$n. DB Attributes:</b>\n";
  301.     print "<tr><td>domain:<td><input name=db".$n."_domain
  302.           value=\"$db_attr{'domain'}\"> \n";
  303.     print "<tr><td>file:<td><input name=db".$n."_file
  304.           value=\"$db_attr{'file'}\"> \n";
  305.     print "<tr><td>db_hash:<td><input name=db".$n."_db_hash
  306.           value=\"$db_attr{'db_hash'}\"> (btree)\n";
  307.     print "<tr><td>null_extend_key:<td><input name=db".$n."_null_extend_key
  308.           value=\"$db_attr{'null_extend_key'}\"> (false)\n";
  309.     print "<p>\n";
  310. }
  311.  
  312. sub print_ldap {
  313.     $n = $_[0];
  314.     print "<tr><td colspan=2><b>$n. LDAP Attributes:</b>\n";
  315.     print "<tr><td>error_timeout:<td><input name=ldap".$n."_error_timeout
  316.           value=\"$ldap_attr{'error_timeout'}\"> (5 s)\n";
  317.     print "<tr><td>open_timeout:<td><input name=ldap".$n."_open_timeout
  318.           value=\"$ldap_attr{'open_timeout'}\"> (2 s)\n";
  319.     print "<tr><td>search_timeout:<td><input name=ldap".$n."_search_timeout
  320.           value=\"$ldap_attr{'search_timeout'}\"> (2 s)\n";
  321.     print "<tr><td>max_requests:<td><input name=ldap".$n."_max_requests
  322.           value=\"$ldap_attr{'max_requests'}\"> (3 queries)\n";
  323.     print "<p>\n";
  324. }
  325.  
  326. sub assemble_attrs {
  327.     local ($num) = $_[0];
  328.  
  329.     if    ($num == 1) { %vals = %final_map; } 
  330.     elsif ($num == 2) { %vals = %final_one; } 
  331.     elsif ($num == 3) { %vals = %final_two; } 
  332.     elsif ($num == 4) { %vals = %final_three; }
  333.     foreach $key (keys %vals) {
  334.         delete $vals{$key} if ($vals{$key} eq '!!!');
  335.     }
  336.  
  337.     @keys = keys(%vals);
  338.     $num_keys = $#keys;
  339.     if ($num_keys >= 0) {
  340.         $count = 0;
  341.         $attr_string = "(";
  342.         while ($count <= $num_keys) {
  343.             $attr_string .= $keys[$count]; 
  344.             if ($vals{$keys[$count]} ne "true") {
  345.                 if ($vals{$keys[$count]} =~ /\s/) {
  346.                     $attr_string .= "=\"$vals{$keys[$count]}\"";
  347.                 } else {
  348.                     $attr_string .= "=$vals{$keys[$count]}";
  349.                 }
  350.             }
  351.             $attr_string .= "," if ($count < $num_keys); 
  352.             $count++;
  353.         }
  354.         $attr_string .= ")";
  355.     } else {
  356.         $attr_string = "";
  357.     }
  358.     $attr_string =~ s/\'/\"/g;
  359.     $attr_string =~ s/\"\"/\"/g;
  360. }
  361.  
  362. sub read_attrs {
  363.     undef @attr_list; $index = 1;
  364.     while ($query->param("map_attr".$index)) {
  365.         push(@attr_list, $query->param("map_attr".$index));
  366.         $index++;
  367.     }
  368.     foreach $arg (@attr_list) {
  369.         ($name, $value) = split("=", $arg);
  370.         $map_attr{$name} = $value;
  371.         $map_attr{$name} = "true" if (!$value);
  372.     }
  373.  
  374.     undef @attr_list; $index = 1;
  375.     while ($query->param("files".$index)) {
  376.         push(@attr_list, $query->param("files".$index));
  377.         $index++;
  378.     }
  379.     foreach $arg (@attr_list) {
  380.         ($name, $value) = split("=", $arg);
  381.         $files_attr{$name} = $value;
  382.         $files_attr{$name} = "true" if (!$value);
  383.     }
  384.  
  385.     undef @attr_list; $index = 1;
  386.     while ($query->param("dns".$index)) {
  387.         push(@attr_list, $query->param("dns".$index));
  388.         $index++;
  389.     }
  390.     foreach $arg (@attr_list) {
  391.         ($name, $value) = split("=", $arg);
  392.         $dns_attr{$name} = $value;
  393.         $dns_attr{$name} = "true" if (!$value);
  394.     }
  395.  
  396.     undef @attr_list; $index = 1;
  397.     while ($query->param("nis".$index)) {
  398.         push(@attr_list, $query->param("nis".$index));
  399.         $index++;
  400.     }
  401.     foreach $arg (@attr_list) {
  402.         ($name, $value) = split("=", $arg);
  403.         $nis_attr{$name} = $value;
  404.         $nis_attr{$name} = "true" if (!$value);
  405.     }
  406.  
  407.     undef @attr_list; $index = 1;
  408.     while ($query->param("nisserv".$index)) {
  409.         push(@attr_list, $query->param("nisserv".$index));
  410.         $index++;
  411.     }
  412.     foreach $arg (@attr_list) {
  413.         ($name, $value) = split("=", $arg);
  414.         $yp_attr{$name} = $value;
  415.         $yp_attr{$name} = "true" if (!$value);
  416.     }
  417.  
  418.     undef @attr_list; $index = 1;
  419.     while ($query->param("mdbm".$index)) {
  420.         push(@attr_list, $query->param("mdbm".$index));
  421.         $index++;
  422.     }
  423.     foreach $arg (@attr_list) {
  424.         ($name, $value) = split("=", $arg);
  425.         $mdbm_attr{$name} = $value;
  426.         $mdbm_attr{$name} = "true" if (!$value);
  427.     }
  428.  
  429.     undef @attr_list; $index = 1;
  430.     while ($query->param("ndbm".$index)) {
  431.         push(@attr_list, $query->param("ndbm".$index));
  432.         $index++;
  433.     }
  434.     foreach $arg (@attr_list) {
  435.         ($name, $value) = split("=", $arg);
  436.         $ndbm_attr{$name} = $value;
  437.         $ndbm_attr{$name} = "true" if (!$value);
  438.     }
  439.  
  440.     undef @attr_list; $index = 1;
  441.     while ($query->param("db".$index)) {
  442.         push(@attr_list, $query->param("db".$index));
  443.         $index++;
  444.     }
  445.     foreach $arg (@attr_list) {
  446.         ($name, $value) = split("=", $arg);
  447.         $db_attr{$name} = $value;
  448.         $db_attr{$name} = "true" if (!$value);
  449.     }
  450.  
  451.     undef @attr_list; $index = 1;
  452.     while ($query->param("ldap".$index)) {
  453.         push(@attr_list, $query->param("ldap".$index));
  454.         $index++;
  455.     }
  456.     foreach $arg (@attr_list) {
  457.         ($name, $value) = split("=", $arg);
  458.         $ldap_attr{$name} = $value;
  459.         $ldap_attr{$name} = "true" if (!$value);
  460.     }
  461. }
  462.  
  463. sub set_attrs {
  464.     @names = $query->param;
  465.     foreach $key (@names) {
  466.         next if (($key eq 'doit') || ($key eq 'page2'));
  467.         next if (($key =~ /^lib\d+$/));
  468.  
  469.         $name = $key;
  470.         $number = $key;
  471.  
  472.         if (! $query->param($key)) { $attr_val = "!!!"; } 
  473.         else { $attr_val = $query->param($key); }
  474.         $number =~ s/[^\d]//g;
  475.         $name =~ s/^\w+\d_//g;
  476.  
  477.         if    ($number == 1) { $final_map{$name} = $attr_val; } 
  478.         elsif ($number == 2) { $final_one{$name} = $attr_val; } 
  479.         elsif ($number == 3) { $final_two{$name} = $attr_val; } 
  480.         elsif ($number == 4) { $final_three{$name} = $attr_val; }
  481.     }
  482. }
  483.